package com.libgdxbar.pvzlikegame;

import com.badlogic.gdx.Game;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.libgdxbar.pvzlikegame.entities.EntityGroup;
import com.libgdxbar.pvzlikegame.screens.ScreenManager;
import com.libgdxbar.pvzlikegame.screens.gamescreens.ExceptionCaptorTestScreen;
import com.libgdxbar.pvzlikegame.screens.gamescreens.MainGameScreen;
import com.libgdxbar.pvzlikegame.screens.gamescreens.ShapeAndTextureEntityScreen;
import com.libgdxbar.pvzlikegame.screens.gamescreens.SplashScreen;
import com.libgdxbar.pvzlikegame.screens.gamescreens.UISkinThemeScreen;
import com.libgdxbar.pvzlikegame.systems.GameCameraSystem;
import com.libgdxbar.pvzlikegame.systems.UpdateSystem;
import com.libgdxbar.pvzlikegame.systems.render.RenderSystem;

// 主游戏类
public class MainGame extends Game {

	@Override
	public void create() {
		EntityGroup group = EntityGroup.getInstance();
		OrthographicCamera camera = new OrthographicCamera();
		GameCameraSystem cameraSystem = new GameCameraSystem(camera);
		group.addSystem(cameraSystem);
		group.addSystem(new UpdateSystem());
		group.addSystem(new RenderSystem(cameraSystem::getCamera));

		// TODO 在游戏一开始就注册所有屏幕 执行了所有屏幕的构造函数 在游戏规模扩大时可能影响性能
		ScreenManager.getInstance()
			.addScreen(new SplashScreen())
			.addScreen(new UISkinThemeScreen())
			.addScreen(new ShapeAndTextureEntityScreen())
			.addScreen(new ExceptionCaptorTestScreen())
			.addScreen(new MainGameScreen())
			.setLaunchScreen(SplashScreen.class);
	}

	@Override
	public void render() {
		ScreenManager.getInstance().render();
	}

	@Override
	public void resize(int width, int height) {
		ScreenManager.getInstance().resize(width, height);
	}

	@Override
	public void dispose() {
		ScreenManager.getInstance().dispose();
	}
}
